package org.numanint.code;

import java.util.HashMap;

public class ConventUtils {
	public final static String TABLE_NAME_SPLIT_CHAR = "_";
	
	public static String upperFirstChar(String str){
		return str.substring(0,1).toUpperCase().concat(str.substring(1,str.length()));
	}
	
	public static String lowerFirstChar(String str){
		return str.substring(0,1).toLowerCase().concat(str.substring(1,str.length()));
	}
	
	// tablename to classname
	public static String t2c(String tableName){
		StringBuffer className = new StringBuffer();
		String[] splitString = tableName.split(TABLE_NAME_SPLIT_CHAR);
		for(int i=0;i<splitString.length;i++)
			className.append(upperFirstChar(splitString[i].toLowerCase()));
		return className.toString();
	}

	
	public static String typeFmt(String typeName){
		HashMap<String,String> dialectType = new HashMap<String,String>();
		dialectType.put("CHAR","String");
		dialectType.put("VARCHAR2","String");
		dialectType.put("NCHAR","String");
		dialectType.put("NVARCHAR2","String");
	    dialectType.put("DATE","String");
	    dialectType.put("LONG","Long");
	    dialectType.put("NUMBER","Long");
	    dialectType.put("REAL","Long");
	    dialectType.put("FLOAT","Float");
	    dialectType.put("DECIMAL","Float");
	    dialectType.put("INTEGER","Integer");
	    dialectType.put("INT","Integer");
	    dialectType.put("BIT","Integer");
	    dialectType.put("VARCHAR","String");
	    dialectType.put("DATETIME","String");
	    dialectType.put("LONGTEXT","String");
	  
	    return dialectType.get(typeName)==null?typeName:dialectType.get(typeName);
	}
	
}
